#include<iostream>
#include<vector>
#include<algorithm>

using std::cin;
using std::cout;
using std::vector;
using std::min;

const int MAGIC_CONST = 268435459;

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<bool> > is_clear(n);
    vector<vector<int> > path_number(n);
    for (int i = 0; i < n; ++i) {
        is_clear[i].resize(m);
        path_number[i].resize(m);
        for (int j = 0; j < m; ++j) {
            int is_cage_clear;
            cin >> is_cage_clear;
            is_clear[i][j] = is_cage_clear;
            path_number[i][j] = 0;
        }
    }
    if (!is_clear[0][0] || !is_clear[n - 1][m - 1]) {
        cout << 0;
        return 0;
    }
    path_number[0][0] = 1;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (i != 0 && is_clear[i - 1][j]) {
                path_number[i][j] = (path_number[i][j] + path_number[i - 1][j]) % MAGIC_CONST;
            }
            if (j != 0 && is_clear[i][j - 1]) {
                path_number[i][j] = (path_number[i][j] + path_number[i][j - 1]) % MAGIC_CONST;
            }
        }
    }
    cout << (path_number[n - 1][m - 1]) % MAGIC_CONST << "\n";
    return 0;
}
